from ultralytics import YOLO


def main():
    model = YOLO('runs/detect/train6/weights/best.pt')  # 确保模型路径正确
    results = model.val(
        data=r'D:\yolov8-2.0-train-image-video\mydata.yaml',  # 使用原始字符串（注意路径前的 r）
        split='val',
        batch=16,
        iou=0.6,
        conf=0.001,
        device='cuda',
        plots=True,
        workers=0  # Windows 必须设置 workers=0 关闭多进程
    )

    # 在 main() 内部打印结果
    print(f"mAP50-95: {results.box.map}")
    print(f"mAP50: {results.box.map50}")
    print(f"Precision: {results.box.p}")
    print(f"Recall: {results.box.r}")


if __name__ == '__main__':
    main()  # 调用主函数执行验证